import ssjkgl from '{platform}/script/views/tjzx/ssjkgl/index';
import {tbody,tleftCheck,tcount} from '{platform}/script/views/table/tableData'
import tableObj from '{platform}/script/pages/table/index';
import search from '{platform}/script/pages/search/index'
var template=require('template');
var events=require('events');
var request = require('{pub}/request');
var func = require('{pub}/function');
return {
    target:'#ssjkgl',
    path:'/ssjkgl/',
    template:ssjkgl, 
    tbHead: {
        leftType:'checkbox',
        bottomCount:false,
        headArr:[{
            name:'税收缴款书编号',type:'pzh',width:100
        },{
            name:'所属税局',type:'companyname',width:85
        },{
            name:'纳税人识别号',type:'skfzjhm',width:85
        },{
            name:'纳税人名称',type:'skfmc',width:85
        },{
            name:'计税金额',type:'wsjehj',width:85,countData:'countWsje'
        },{
            name:'实缴金额',type:'sehj',width:85,countData:'countSehj'
        },{
            name:'税款所属期',type:'skssq',width:85
        },{
            name:'电子税票号码',type:'dzsh',width:85
        },{
            name:'是否作废',type:'trashed',width:85
        },{
            name:'是否重打',type:'reprint',width:85
        },{
            name:'备注',type:'bz',width:85
        }]
    },
    onInit:function(){
        var _that =  this
        var funList=[{
            name:'详细',
            icon:'',
            type:'layInfo',
            data:'layInfo'
        },{
            name:'作废重打',
            icon:'',
            type:'layInfo',
            data:'reset'
        }];
        var slideList={
            rows:4,
            arr:[{
                name:'缴款书编号',
                type:'pzh',
                data:'input',
            },{
                name:'所属税期',
                type:'time',
                data:'date'
            },{
                name:'纳税人名称',
                type:'skfmc',
                data:'input',
            },{
                name:'电子税票号码',
                type:'djbh',
                data:'input'
            },{
                name:'纳税人识别号',
                type:'skfzjhm',
                data:'input'
            },{
                name:'所属税局',
                type:'bmid',
                data:'ztree',
                // option:comoption
            },{
                name:'是否已打印',
                type:'isprint',
                data:'option',
                option:[{
                    id:'Y',
                    value:'是'
                },{
                    id:'N',
                    value:'否'
                }]
            },{
                name:'是否作废',
                type:'fpzl',
                data:'option',
                option:[{
                    id:'Y',
                    value:'是'
                },{
                    id:'N',
                    value:'否'
                }]
            },{
                name:'是否重打',
                type:'reprint',
                data:'option',
                option:[{
                    id:'Y',
                    value:'是'
                },{
                    id:'N',
                    value:'否'
                }]
            }]
        };
        var param = {//导出功能参数
            layInfo:'/tjzx/wspz/detailUrl',
            reset:'/tjzx/wspz/updateTrashedUrl'
        }//
        search.init(_that.element.find('.g-top-view'), {funList:funList,slideList:slideList}, param);
        tableObj.init(_that.element.find('.g-table-view'),{tabHead:this.tbHead},{_that:this,url:'/tjzx/wspz/list',param:{query:'y'},callback:this.reqSsjkgl})
        // this.reqGssk()
    },
    reqSsjkgl:function(res) {//国税税款统计
        var that = this._that;
        if(res.result === 'success') {
            var rows = res.data.queryList;
            var footList = res.data.footerList;
            that.tableData(rows,footList)
        } else {
            message('error', res.message)
        }
    },
    tableData:function(data,footList) {//表格数据处理
        var _that = this,tbHead = this.tbHead.headArr;
            var i,len = data.length, j, jlen = tbHead.length, tbBody = [],countHsjehj = 0,countSehj = 0,tabCount = [];
            for(i=0;i<len;i++) {
                countSehj = func.jisuan('+',countSehj,data[i].sehj);
                countHsjehj = func.jisuan('+',countHsjehj,data[i].hsjehj);
                tbBody.push({
                    id:data[i].id,
                    td:[],
                });
                for(j =0;j<jlen;j++) {
                    if(tbHead[j].type === 'trashed') {
                        data[i][tbHead[j].type]= data[i][tbHead[j].type] === 'Y' ? '是':'否'
                    }
                    if(tbHead[j].type === 'reprint') {
                        data[i][tbHead[j].type]= data[i][tbHead[j].type] === 'Y' ? '是':'否'
                    }


                    tbBody[i].td.push({
                        name:data[i][tbHead[j].type] || '',
                        type:tbHead[j].type
                    });
                }
            }
            for(var cn=0;cn<jlen;cn++){
                var coun = '';
                if(tbHead[cn].countdata == 'sehj') {
                    coun = footList[0].sehj
                }
                if(tbHead[cn].countdata == 'hsjehj') {
                    coun = footList[0].hsjehj
                }
                tabCount.push({
                    countData: coun || '',
                    type:tbHead[cn].type
                })
            }
            $('#tableData').html(template.render(tbody, {tabBody:tbBody}));
            $('#tfixData').html(template.render(tleftCheck, {tabBody:tbBody}));
            $('#tcountData').html(template.render(tcount, {tabCount:tabCount}));
    }
}